home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / network / midi / mx2net20.lzh / MX2NET20 / NETWORK.MOD < prev   
Text File  |  1990-12-15  |  39KB  |  1,178 lines

  1. (*                                                              *)
  2. (*              Copyright 1989 fred brooks LogicTek             *)
  3. (*                                                              *)
  4. (*   First Release                      12/8/87-FGB             *)
  5. (*   Added drive config data routines, clean up VBL code,       *)
  6. (*   Remote time option                 12/17/89-FGB            *)
  7. (*                                                              *)
  8.  
  9. IMPLEMENTATION MODULE NETWORK ;
  10.  
  11. (* --------------------------------------------------------------------------
  12.  
  13.                NETWORK : TWO CPU NETWORK FOR TDI Modula-2/ST
  14.  
  15.    --------------------------------------------------------------------------*)
  16.  
  17. (*$T-,$S-,$A+ *)
  18.  
  19. FROM SYSTEM IMPORT ADDRESS, ADR, SETREG, CODE, REGISTER ,BYTE ,TSIZE;
  20. FROM BIOS   IMPORT BPB ,BConStat ,BConIn, BCosStat, BConOut, Device,
  21.                    MediaChange,MCState,GetBPB,RWAbs,RW,DriveSet,DriveMap;
  22. FROM XBIOS  IMPORT SuperExec,IORec,IORECPTR,IOREC,SerialDevice,
  23.                    GetDateTime,ScreenPhysicalBase;
  24. FROM GEMDOS IMPORT TermRes,Open,Close,SetDate,SetTime ;
  25. IMPORT             GEMDOS;
  26. FROM ASCII  IMPORT SYN,STX,SOH,BEL,CR,LF,ESC;
  27.  
  28. CONST
  29.   MaxSeq          = 1;
  30.   Maxdrives       = 31; (* number of disk drives minus 1 *)
  31.   recsize         = 511;
  32.   retry           = 5;
  33.   MAGIC           = 314159;
  34.   Memdrive        = 31;
  35.   chanwait        = 3;
  36.   debug           = FALSE;
  37.   trace           = FALSE;
  38.   TITLE           = "MX2NET Version 2.0   Fred Brooks  UUCP crash!fgbrooks";
  39.  
  40.   (* Because we dont know what registers the BIOS is using we must use
  41.      the following opcodes to save the registers *)
  42.   MOVEMDEC = 48E7H ;    (* 68000 opcode for MOVEM <regs>,-(A7) *)
  43.   MOVEMINC = 4CDFH ;    (* 68000 opcode for MOVEM (A7)+,<regs> *)
  44.   SAVEREGS = 07FFCH ;   (* Registers D1..A5 for DEC *)
  45.   RESTREGS = 03FFEH ;   (* Registers D1..A5 for INC *)
  46.   RTS = 04E75H ;        (* 68000 return from subroutine opcode *)
  47.  
  48. TYPE
  49.   (* Procedure types to mimic correct sequence for "C" BIOS routines *)
  50.  
  51.   CBPBProc     = PROCEDURE ( CARDINAL ) ;
  52.   CMediaChProc = PROCEDURE ( CARDINAL ) ;
  53.   CRWAbsProc   = PROCEDURE ( CARDINAL, CARDINAL, CARDINAL, ADDRESS, CARDINAL );
  54.   MIDIbuffer   = ARRAY [0..1023] OF CARDINAL;
  55.   SequenceNr   = [0..MaxSeq];
  56.   message      = ARRAY [0..recsize] OF BYTE;
  57.   message1     = ARRAY [0..17] OF BYTE;
  58.   FrameKind    = (ack,data,callreq,callaccp,clearreq,clearconf,
  59.                  resetreq,diag);
  60.   DataKind     = (rdmediareq,rdmediaconf,rdbpbreq,rdbpbconf,
  61.                  rdrwabsreq,rdrwabsconf,memreq,memconf,timereq,timeconf);
  62.   evtype       = (framearrival,cksumerr,timeout,hostready,reset,nothing);
  63.   channel      = (none,local,remote);
  64.  
  65.   frame        = RECORD
  66.                  syn    :       CHAR; (* these are sync chars *)
  67.                  stx    :       CHAR; (* for the frames       *)
  68.                  kind   :       FrameKind;
  69.                  seq    :       SequenceNr;
  70.                  ack    :       SequenceNr;
  71.                  cmd    :       DataKind;
  72.                  rw     :       CARDINAL; (* read or write data *)
  73.                  recno  :       CARDINAL; (* sector for data*)
  74.                  d0     :       LONGCARD; (* data return variable *)
  75.                  info   :       message;
  76.                  cksum  :       CARDINAL;
  77.                END;
  78.  
  79.   framecptr    = POINTER TO framecmd;
  80.  
  81.   framecmd     = RECORD
  82.                  syn    :       CHAR; (* these are sync chars *)
  83.                  stx    :       CHAR; (* for the frames       *)
  84.                  kind   :       FrameKind;
  85.                  seq    :       SequenceNr;
  86.                  ack    :       SequenceNr;
  87.                  cmd    :       DataKind;
  88.                  rw     :       CARDINAL; (* read or write data *)
  89.                  recno  :       CARDINAL; (* sector for data*)
  90.                  d0     :       LONGCARD; (* data return variable *)
  91.                  info   :       message1;
  92.                  cksum  :       CARDINAL;
  93.                END;
  94.  
  95.   control     = RECORD
  96.                  magic          :       LONGCARD;
  97.                  reset          :       BOOLEAN;
  98.                  networkactive  :       BOOLEAN;
  99.                  remotedrive    :       CARDINAL;
  100.                  drivemap       :       DriveSet;
  101.                 nextframetosend :      SequenceNr;
  102.                 frameexpected   :      SequenceNr;
  103.                 sendreset       :      BOOLEAN;
  104.                END;
  105.  
  106.   netmap      = RECORD
  107.                  Remote         :       CARDINAL;
  108.                  Local          :       CARDINAL;
  109.                  Write          :       BOOLEAN;
  110.                 END;
  111.  
  112.   frameptr      =       POINTER TO ARRAY [0..1024] OF BYTE;
  113.  
  114. VAR
  115.  
  116.  
  117.   (* BIOS variables : These can only be accessed with the 68000 in supervisor
  118.      mode. The Modula-2 language allows you to fix the location of variables *)
  119.  
  120.   HDBPB     [0472H] : ADDRESS ;       (* hard disk get Bios Parameter Block *)
  121.   HDRWAbs   [0476H] : ADDRESS ;       (* hard disk read/write abs   *)
  122.   HDMediaCh [047EH] : ADDRESS ;       (* hard disk media change     *)
  123.   EvtCritic [0404H] : ADDRESS ;       (* evt_critic *)
  124.   DriveBits [04C2H] : SET OF [0..31]; (* disk drives present map    *)
  125.   flock     [043EH] : LONGCARD;       (* disk access in progress    *)
  126.   hz200     [04baH] : LONGCARD;       (* 200hz clock counter        *)
  127.  
  128.   NetBits           : SET OF [0..31];
  129.   Dptr              : DriveSet;       (* save original drive map    *)
  130.   Mptr              : LONGCARD;
  131.   charcount,framesize,cksum,recframesize,sndframesize,
  132.   SIZEframe,SIZEframecmd                                : CARDINAL;
  133.  
  134.   networkconnect          :   BOOLEAN; (* DCD = 1 TRUE  *)
  135.   gotframe                :   BOOLEAN;
  136.   framebufferfull         :   BOOLEAN;
  137.   cleartosend             :   BOOLEAN;
  138.   readytosend             :   BOOLEAN;
  139.   requesttosend           :   BOOLEAN;
  140.   framewaiting            :   BOOLEAN;
  141.   OK,installed            :   BOOLEAN;
  142.   gotmediach              :   ARRAY [0..Maxdrives] OF BOOLEAN;
  143.   gotbpb                  :   ARRAY [0..Maxdrives] OF BOOLEAN;
  144.   networkerror            :   BOOLEAN;
  145.   shortframe              :   BOOLEAN;
  146.   vblLock                 :   BOOLEAN;
  147.   rwabsLock               :   BOOLEAN;
  148.   TIMESET                 :   BOOLEAN;
  149.   OneTime                 :   BOOLEAN;
  150.   ChannelLock             :   channel;
  151.   NetMap                  :   ARRAY [0..Maxdrives] OF netmap;
  152.   NetInfo                 :   ARRAY [0..128] OF CHAR;
  153.   statptr                 :   POINTER TO stat;
  154.  
  155.   sframe,rframe,SFRAME,RFRAME                   :   frame;
  156.   rframeptr                                     :   frameptr;
  157.   framecmdptr                                   :   framecptr;
  158.   sframecmdptr                                  :   framecptr;
  159.   event                                         :   evtype;
  160.   C                                             :   control;
  161.   S                                             :   stat;
  162.   recchar                                       :   LONGCARD;
  163.   result,i,i1,mediacount,handle                 :   INTEGER;
  164.   D0ptr                                         :   POINTER TO LONGCARD;
  165.   wsector,drvnr,d,R                             :   CARDINAL;
  166.   rbuffer                                       :   MIDIbuffer;
  167.   rbptr,kbdiorec                                :   IORECPTR;
  168.   numBytes,sec,min,hour,time,count              :   LONGCARD ;
  169.   status                                        :   LONGINT ;
  170.   sframeptr                                     :   frameptr;
  171.  
  172.   (* The following are saved copies of the BIOS variables so that the real
  173.      hard disk routines can be called if a hard disk access is requested. *)
  174.  
  175.   SaveHDBPB      : CBPBProc ;     (* hard disk get Bios Parameter Block *)
  176.   SaveHDRWAbs    : CRWAbsProc ;   (* hard disk read/write abs *)
  177.   SaveHDMediaCh  : CMediaChProc ; (* hard disk media change *)
  178.   SaveCritic     : PROC;
  179.  
  180.   (* NETWORK control *)
  181.  
  182.   NetworkBPB  : ARRAY [0..Maxdrives] OF BPB ; (* BIOS Parameter block